<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
 version="1.0"  
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:are="http://cedr.mfcr.cz/xml_doc/schemas/ares/ares_request/v_1.0.0"
 xml:space="default">

<xsl:output method="html" encoding="UTF-8"/> 

  <xsl:template match="/">
    <xsl:apply-templates select="//are:Ares_dotazy"/>
  </xsl:template>

  <xsl:template match="//are:Ares_dotazy">

    <xsl:variable name="lnAtCount"><xsl:value-of select="@dotaz_pocet"/></xsl:variable>
    <xsl:variable name="lnReCount"><xsl:value-of select="count(Dotaz)"/></xsl:variable>
    <xsl:if test="not($lnAtCount=$lnReCount)">
<Error>
<Error_ID>1</Error_ID>
<Error_text>Nesouhlasi pocet polozek dotazu v atributu dotaz_pocet a pocet elementu &lt;Dotaz&gt;</Error_text>
</Error>
    </xsl:if>

    <xsl:if test="($lnAtCount &lt; 1 or $lnAtCount &gt; 100)">
<Error>
<Error_ID>1b</Error_ID>
<Error_text>V atributu  dotaz_pocet je hodnota mimo interval 1 - 100</Error_text>
</Error>
    </xsl:if>

    <xsl:for-each select="Dotaz">

	<xsl:variable name="lnICOCount" select="count(Klicove_polozky/are:ICO)"/>
	<xsl:if test="$lnICOCount &gt; 1">
<Error>
<Record_ID><xsl:value-of select="Pomocne_ID"/></Record_ID>
<Error_ID>2</Error_ID>
<Error_text>Lze zadat pouze jedno ICO</Error_text>
</Error>
	</xsl:if>

	<xsl:variable name="lnRCCount" select="count(Klicove_polozky/are:Rodne_cislo)"/>
	<xsl:if test="$lnRCCount &gt; 1">
<Error>
<Record_ID><xsl:value-of select="Pomocne_ID"/></Record_ID>
<Error_ID>3</Error_ID>
<Error_text>Lze zadat pouze jedno rodne cislo</Error_text>
</Error>
	</xsl:if>

	<xsl:variable name="lnOFCount" select="count(Klicove_polozky/are:Obchodni_firma)"/>
	<xsl:if test="$lnOFCount &gt; 1">
<Error>
<Record_ID><xsl:value-of select="Pomocne_ID"/></Record_ID>
<Error_ID>4</Error_ID>
<Error_text>Lze zadat pouze jeden nazev obchodni firmy</Error_text>
</Error>
	</xsl:if>

	<xsl:variable name="lnMaxCount" select="count(Max_pocet)"/>
	<xsl:if test="$lnMaxCount &gt; 1">
<Error>
<Record_ID><xsl:value-of select="Pomocne_ID"/></Record_ID>
<Error_ID>5</Error_ID>
<Error_text>Elementu Max_pocet je uvedeno: <xsl:value-of select="$lnMaxCount"/></Error_text>
</Error>
	</xsl:if>

	<xsl:variable name="lnDCount" select="count(Datum_platnosti)"/>
	<xsl:if test="$lnDCount &gt; 1">
<Error>
<Record_ID><xsl:value-of select="Pomocne_ID"/></Record_ID>
<Error_ID>6</Error_ID>
<Error_text>Elementu Datum_platnosti je uvedeno: <xsl:value-of select="$lnDCount"/></Error_text>
</Error>
	</xsl:if>

	<xsl:variable name="lnTypCount" select="count(Typ_vyhledani)"/>
	<xsl:if test="$lnTypCount &gt; 1">
<Error>
<Record_ID><xsl:value-of select="Pomocne_ID"/></Record_ID>
<Error_ID>7</Error_ID>
<Error_text>Elementu Typ_vyhledani je uvedeno: <xsl:value-of select="$lnTypCount"/></Error_text>
</Error>
	</xsl:if>

	<xsl:variable name="lnTypRCount" select="count(Typ_registru)"/>
	<xsl:if test="$lnTypRCount &gt; 1">
<Error>
<Record_ID><xsl:value-of select="Pomocne_ID"/></Record_ID>
<Error_ID>8</Error_ID>
<Error_text>Elementu Typ_registru je uvedeno: <xsl:value-of select="$lnTypRCount"/></Error_text>
</Error>
	</xsl:if>

	<xsl:variable name="lnTypKCount" select="count(Typ_registru/Kod)"/>
	<xsl:if test="$lnTypKCount &gt; 1">
<Error>
<Record_ID><xsl:value-of select="Pomocne_ID"/></Record_ID>
<Error_ID>9</Error_ID>
<Error_text>Elementu Kod je uvedeno: <xsl:value-of select="$lnTypKCount"/></Error_text>
</Error>
	</xsl:if>

	<xsl:variable name="lnIDCount" select="count(Pomocne_ID)"/>
	<xsl:if test="$lnIDCount &gt; 1">
<Error>
<Record_ID><xsl:value-of select="Pomocne_ID"/></Record_ID>
<Error_ID>10</Error_ID>
<Error_text>Elementu Pomocne_ID je uvedeno: <xsl:value-of select="$lnIDCount"/></Error_text>
</Error>
	</xsl:if>

    </xsl:for-each>		

  </xsl:template>            
</xsl:stylesheet>
